package io.sage.modules.readsenseapi.controller;

import java.util.List;
import com.github.pagehelper.PageInfo;
import io.sage.modules.flow.service.FlowDeviceService;
import io.sage.modules.readsenseapi.entity.BFlowDevice;
import io.sage.modules.readsenseapi.vo.DeviceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.sage.common.utils.R;

/**
 * 
 *
 * @author zhang
 * @date 2019-08-06 18:10:59
 */
@RestController
@RequestMapping("flow/flowdevice")
public class FlowDeviceController {
    @Autowired
    private FlowDeviceService flowDeviceService;
    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("flow:flowdevice:list")
    public R list(){
        List<BFlowDevice> bFlowDevices = flowDeviceService.selectFlowDeviceList(null);
        PageInfo<BFlowDevice> pageInfo = new PageInfo<BFlowDevice>(bFlowDevices);// 传入list就可以了
        return R.ok().put("flowDevices",pageInfo);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("flow:flowdevice:info")
    public R info(@PathVariable("id") String id){
        BFlowDevice flowDevice = flowDeviceService.selectByPrimaryKey(id);
        return R.ok().put("flowDevice", flowDevice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("flow:flowdevice:save")
    public R save(@RequestBody DeviceVo deviceVo){
        System.out.println("deviceVo=23="+deviceVo);
        int insert = flowDeviceService.insert(deviceVo);
        if(insert>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("flow:flowdevice:update")
    public R update(@RequestBody DeviceVo flowDevice){
        int upd = flowDeviceService.updateByPrimaryKeySelective(flowDevice);
        if(upd>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("flow:flowdevice:delete")
    public R delete(@RequestBody String[] ids){
        int del = flowDeviceService.deleteBatchIds(ids);
        if(del>0){
            return R.ok();
        }
        return R.error();
    }

}
